package com.imufe.chemicalenterprisedangerwarning.controller;

import com.imufe.chemicalenterprisedangerwarning.entity.query.*;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.CheckUnitDetailedVO;
import com.imufe.chemicalenterprisedangerwarning.exception.ValidationException;
import com.imufe.chemicalenterprisedangerwarning.service.CheckUnitService;
import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 检查模块表 前端控制器
 * </p>
 *
 * @author BaiBan
 * @since 2022-10-06
 */
@Api(tags = "检查模块")
@RestController
@RequestMapping("/check-unit")
public class CheckUnitController {

    @Autowired
    CheckUnitService service;

    @ApiOperation(value = "模块列表", notes = "按企业返回模块列表")
    @GetMapping("/{enterpriseId}")
    public ResponseEntity<List<CheckUnitDetailedVO>> page(@PathVariable(value = "enterpriseId") Long enterpriseId) {
        List<CheckUnitDetailedVO> list = service.list(enterpriseId);
        return ResponseEntity.success(list);
    }

    @ApiOperation(value = "新增", notes = "新增一个模块")
    @PostMapping("/create")
    public ResponseEntity<CheckUnitDetailedVO> create(@RequestBody @Validated(CreateGroup.class) CheckUnitQuery query) throws ValidationException {
        CheckUnitDetailedVO detailedVO = service.create(query);
        return ResponseEntity.success(detailedVO);
    }

    @ApiOperation(value = "修改", notes = "修改一个模块，返回修改后的模块信息")
    @PutMapping("/update")
    public ResponseEntity<CheckUnitDetailedVO> update(@RequestBody @Validated(UpdateGroup.class) CheckUnitQuery query) throws ValidationException {
        CheckUnitDetailedVO detailedVO = service.update(query);
        return ResponseEntity.success(detailedVO);
    }
}
